package com.common.library.Utils;

import android.util.Log;

/**
 * Created by Administrator on 2018/3/19 0019.
 */

public class LogUtil {

    private static final boolean log_switch = true;
    private static String className;//类名
    private static String methodName;//方法名
    private static int lineNumber;//行数

    public static void e(String log) {
        if (!log_switch) {
            return;
        }
        getMethodNames(new Throwable().getStackTrace());
        Log.e(className, createLog(log));
    }

    private static String createLog(String log) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(methodName);
        buffer.append("(").append(className).append(":").append(lineNumber).append(")");
        buffer.append(log);
        return buffer.toString();
    }

    private static void getMethodNames(StackTraceElement[] sElements) {
        className = sElements[1].getFileName();
        methodName = sElements[1].getMethodName();
        lineNumber = sElements[1].getLineNumber();
    }

}
